package cn.liurong.spring.view.config;

import javax.servlet.Filter;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * servlet3.0才支持注解形式的java文件配置
 * 
 * @author liu.r
 *
 */
public class WebInitializer extends
		AbstractAnnotationConfigDispatcherServletInitializer {

	// 加载spring相关内容
	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[] { SpringConfig.class };
	}

	// 加载springmvc相关内容
	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] { WebMVCConfig.class };
	}

	// 配置映射路径
	@Override
	protected String[] getServletMappings() {
		return new String[] { "*.do" };
	}

	 /* 
     * 注册过滤器，映射路径与DispatcherServlet一致，路径不一致的过滤器需要注册到另外的WebApplicationInitializer中 
     */
	@Override
	protected Filter[] getServletFilters() {
		CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
		encodingFilter.setEncoding("utf-8");
		encodingFilter.setForceEncoding(true);
		return new Filter[] { encodingFilter };
	}
	
}